using System.Collections.Generic;

namespace Lync.Widget.Library.Repositories
{
    public abstract class CacheDictionary<T>
    {
        internal Dictionary<string, IList<T>> Dictionary { get; private set; }

        public void Add(string cacheKey, IList<T> items)
        {
            if (items == null)
            {
                return;
            }

            if (Dictionary.ContainsKey(cacheKey))
            {
                Dictionary[cacheKey] = items;
            }
            else
            {
                Dictionary.Add(cacheKey, items);
            }
        }

        public bool Exists(string cacheKey)
        {
            return Dictionary.ContainsKey(cacheKey);
        }

        public IList<T> Get(string cacheKey)
        {
            if (Dictionary.ContainsKey(cacheKey))
                return Dictionary[cacheKey];
            return (IList<T>) default(T);
        }
        protected CacheDictionary()
        {
            Dictionary = new Dictionary<string, IList<T>>();
        }
    }
}